<?php
    namespace App\Http\Controllers\home;
    use App\Http\Controllers\Controller;
    use Illuminate\Support\Facades\Input;
    use DB;
    class CollectController extends Controller{
            public function collect_list(){
                return view('home.collect.collect_list');
            }
            public function collect_add($arr){
                $array = explode(',', $arr);
                $collect = DB::table('mo_goods')->where(array('g_id'=>$array[0]))->first();
                $shi = DB::table('mo_collect')->where(array('g_id'=>$array[0],'u_id'=>$array[1]))->first();
                $num = $collect->g_collect;
                if(!empty($shi)){
                    DB::table('mo_collect')->where(array('g_id'=>$array[0],'u_id'=>$array[1]))->delete();
                    $g_collect = $num-1;
                    DB::table('mo_goods')->where(array('g_id'=>$array[0]))->update(['g_collect'=>$g_collect]);
                }else{
                    $time = time();
                    DB::table('mo_collect')->insert([
                        'g_id' => $array[0],
                        'collect_time' =>$time,
                        'u_id' => $array[1],
                    ]);
                    $g_collect = $num + 1;
                    DB::table('mo_goods')->where(array('g_id'=>$array[0]))->update(['g_collect'=>$g_collect]);
                }
                return $g_collect;
            }
       }
?>

